SVG fail

2018-05-18 19:07:50

For my previous post, I originally created the image of the cardioid envelope in SVG (scalable vector graphics) format. This format is nice for mathematical diagrams or plots because it's sharp, and stays sharp when you resize it (it scales nicely).

Unfortunately, WordPress doesn't like SVG; it won't render these out of the box (it doesn't support that image format). It turns out there are plug-ins that will do this for you. I tried one; it didn't work properly---all it rendered were the red lines (not the circle or the blue cardioid curve). I'm not sure why. But I learned WordPress doesn't support SVG because SVG is regarded as inherently risky: it's not an ordinary image format, but instead is an XML format that allows the programmer to include JavaScript code. This is dangerous, because it enables malicious code to be injected into a WordPress site. After further reading, I get the impression that these third-party SVG plug-ins either ignore the security issue, or offer a solution ('sanitizing' SVG code) that is not regarded as well-tested or reliable.

So I decided to not use SVG. If I wish to put a mathematical diagram into a WordPress post, I'll use JPEG or PNG; I used PNG for the cardioid envelope in my previous post. The route to this is: Use Python to write LaTeX/PSTricks code to draw the diagram, in a PDF document. Open that document using GIMP; crop or adjust the image as desired, and then export in PNG format. This has the disadvantage that the image will degrade if it is resized larger (pixels will show). But this route does have a big advantage: It's easy to put mathematical notation in an image using LaTeX/PSTricks, but not so easy in SVG. (It can be done: you have to insert 'foreign' elements into SVG code, containing MathJax code. The results can be temperamental.)